/**************************************************************************
 *
 *        Copyright (c) 2007-2008 by Sunplus mMedia Inc., Ltd.
 *
 *  This software is copyrighted by and is the property of Sunplus
 *  mMedia Inc., Ltd. All rights are reserved by Sunplus mMedia
 *  Inc., Ltd. This software may only be used in accordance with the
 *  corresponding license agreement. Any unauthorized use, duplication,
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice MUST not be removed or modified without prior
 *  written consent of Sunplus mMedia Inc., Ltd.
 *
 *  Sunplus mMedia Inc., Ltd. reserves the right to modify this
 *  software without notice.
 *
 *  Sunplus mMedia Inc., Ltd.
 *  19-1, Innovation First Road, Science-Based Industrial Park,
 *  Hsin-Chu, Taiwan, R.O.C.
 *
 **************************************************************************/
#ifndef __SP1K_UTILITY_H__
#define __SP1K_UTILITY_H__

/** \file sp1k_util_api.h
 * @brief		Spca1528 utility related interfaces (Timer/RT/SuspenResume/Photoframe/datestamp).
 */

/**************************************************************************
 *                            H E A D E R   F I L E S
 **************************************************************************/
#include "general.h"
#include "utility.h"
#include "timer.h"
#include "sp1k_def.h"

/**************************************************************************
 *                           C O N S T A N T S
 **************************************************************************/
typedef enum {
	SP1K_GPIO_BYTE_GEN1  = 2,   /* gpio[15:8]     */
	SP1K_GPIO_BYTE_GEN2  = 3,   /* gpio[23:16]    */
	SP1K_GPIO_BYTE_DISP0 = 9,   /* tvegpio[7:0]   */
	SP1K_GPIO_BYTE_DISP1 = 10,  /* tvegpio[15:8]  */
	SP1K_GPIO_BYTE_DISP2 = 11,  /* tvegpio[21:16] */
	SP1K_GPIO_BYTE_P1    = 12,  /* p1[7:0]        */
} sp1kGpioByte_e;

typedef enum {
	SP1K_PRV_BLEND_PHOTOFRM = PRV_BLEND_PHOTOFRM,
	SP1K_PRV_BLEND_ROTATION = PRV_BLEND_ROTATION,
	SP1K_PRV_BLEND_END      = PRV_BLEND_END,
} sp1kPrvBlendMode_e;

enum {
    SP1K_DS_PARAM_FONT_PASTETHD = 0,
    SP1K_DS_PARAM_STAMP_PASTETHD,

    SP1K_DS_PARAM_MAX
};

/**************************************************************************
 *                              M A C R O S
 **************************************************************************/
#ifdef SP1K_DOXY_GEN
/**
 * @fn void sp1kPwrOffCfg(UINT8 enable, UINT32 delay)
 * @brief	configure power off process when battery low
 * @param none
 * @retval 1: the power off process is running
                0: the power off process is stopped
 */
void sp1kPwrOffCfg(UINT8 enable, UINT32 delay);

/**
 * @fn UINT8 sp1kPwrOffProcChk(void)
 * @brief	query the status of power off process
 * @param[in] enable	 enable/disable power off process
 * @param[in] delay	 the delay time of power off process. The time unit is 10ms,
                                    delay = 0 means power off immediately.
 * @retval none
 */
UINT8 sp1kPwrOffProcChk(void);

/**
 * @fn void sp1kTimeDelay1s(void)
 * @brief	Software timer delay (1S).
 * @param none
 * @retval none
 */
void sp1kTimeDelay1s(void);

/**
 * @fn void sp1kTimeDelay1ms(void)
 * @brief	Software timer delay (1ms).
 * @param none
 * @see sp1kTimeDelay1ms()
 * @retval none
 */
void sp1kTimeDelay1ms(void);

/**
 * @fn void sp1kTimer1Start(void)
 * @brief	Start to count timer1. The count value is defined by sp1kTimer1Config().
 * @param none
 * @see sp1kTimer1Config()
 * @retval none
 */
void sp1kTimer1Start(void);

/**
 * @fn void sp1kTimer1Stop(void)
 * @brief	Stop to count timer1.
 * @param none
 * @see sp1kTimer1Config()
 * @retval none
 */
void sp1kTimer1Stop(void);

/**
 * @fn void sp1kTimer1Config(UINT32 Period, pTmrFunc pFunc, UINT8* pFuncPara)
 * @brief	This service allows to register a call back function by timer1 interrupt.
 * @param[in] Period	 Timer1 period setting. Set to TH1,TL1. The time unit is ms
 * @param[in] pFunc      Specifies the call back function pointer
 * @param[in] pFuncPara	 Specify the parameter pass to the registered function.
*\n                                      That means you can't register a fucntion with more than one parameter, Using a struct pointer may be a good idea.
 * @retval none
 */
void sp1kTimer1Config(UINT32 Period, pTmrFunc pFunc, UINT8* pFuncPara);

#else
#define sp1kTimeDelay1s     DELAY_1s
#define sp1kTimeDelay1ms    DELAY_1ms

#define sp1kTimer1Start     TIMER1_Start
#define sp1kTimer1Stop      TIMER1_Stop
#define sp1kTimer1Config    TIMER1_Config
#define sp1kPwrOffCfg       TIMER0_PowerOffCfg
#define sp1kPwrOffProcChk   TIMER0_PowerOffProcChk
#endif

/**************************************************************************
 *                          D A T A    T Y P E S
 **************************************************************************/

/**************************************************************************
 *                         G L O B A L    D A T A
 **************************************************************************/

/**************************************************************************
 *                 E X T E R N A L    R E F E R E N C E S
 **************************************************************************/

/**************************************************************************
 *               F U N C T I O N    D E C L A R A T I O N S
 **************************************************************************/
/**
 * @fn void sp1kPvPhotofrmModeSet(UINT8 mode)
 * @brief	Select blending mode.
 *
 * @param[in] mode     lending mode
 *\n                   SP1K_PRV_BLEND_PHOTOFRM : Photoframe mode (Default)
 *\n                   SP1K_PRV_BLEND_ROTATION: Rotation
 * @retval none
 */
void sp1kPvPhotofrmModeSet(UINT8 mode);

/**
 * @fn void sp1kPvPhotofrmEnable(UINT8 enable)
 * @brief	Enable/disable photo frame at preview mode.
 *
 *          Caller needs to load the selected photo frame to  K_SDRAM_ImagePlaybackBufAddr before enable the function.
 *\n         The buffer in K_SDRAM_ImagePlaybackBufAddr will be blended to each preview buffer about to be shown.
 * @param[in] enable   enable/disable photo frame
 *\n                   0: disable photframe eature at preview mode
 *\n                   1: enable photo frame feature at preview mode
 * @retval none
 */
void sp1kPvPhotofrmEnable(UINT8 enable);

/**
 * @fn void sp1kRTCInit(void)
 * @brief	RTC initialization.
 *
 *           This function should be called once in the system initial.
 *\n         This function will get the reliable code and set a default value if the reliable code is not correct.
 *\n         The initial value is 2008/1/1 12:00
 * @param	none
 * @retval 	none
 */

void sp1kRTCInit(void);

/**
 * @fn UINT8 sp1kSuspendResume(void)
 * @brief	Force system enter suspend state and wait for INT0 event to resume system.
 *
 *          System designer usually set some GPIO pins as interrupt function for resuming system.
 * @param	none
 * @retval error code -  success: 0, fail: 1
 */
UINT8 sp1kSuspendResume(void);

/**
 * @fn void sp1kLoadDateStampData( void )
 * @brief	Load datestamp YUV data to specific DRAM buffer address(K_SDRAM_GrafFontBufAddr)
 * @param	none
 * @retval 	none
 */
void sp1kLoadDateStampData( void );

/**
 * @fn void sp1kDateStampCustomStrSet(UINT8 *str)
 * @brief	Set the custom string for date stamp. 
 * @param	str : Specify the custom string.
 * @retval 	none
 */
void sp1kDateStampCustomStrSet(UINT8 *str);

/**
* @fn void sp1kDateStampParamSet(UINT8 paraId,UINT16 value)
* @brief   Set parameters for date stamp
* @param[in] paraId	 
* @param[in] value	
* @retval void
*/
void sp1kDateStampParamSet(UINT8 paraId, UINT16 value);

/**
* @fn UINT16 sp1kDateStampParamGet(UINT8 paraId)
* @brief   Get parameters for date stamp
* @param[in] paraId	 
* @retval param value	
*/
UINT16 sp1kDateStampParamGet(UINT8 paraId);

/**
 * @fn UINT8 sp1kUsbPccamStart(void)
 * @brief	Start PCCAM by different resolution. (resolution index is sent by vendor command 0x25)
 * @param	none
 * @retval      none
 */
void sp1kUsbPccamStart(void);

/**
 * @fn UINT8 sp1kUsbPccamStop(void)
 * @brief	Stop PCCAM and enable display module.
 * @param	none
 * @retval      none
 */
void sp1kUsbPccamStop( void );

/**
 * @fn void sp1kGpioByteFuncSet(UINT8 byteId, UINT8 msk, UINT8 func)
 * @brief	Set gpio function in byte.
 * @param	byteId :  SP1K_GPIO_BYTE_GEN1 for GPIO[15:14];
 *					  SP1K_GPIO_BYTE_GEN2 for GPIO[17:16];
 *                    SP1K_GPIO_BYTE_P1 for P1[7:0].
 * @param	msk : bitmap mask. please refer to param 'func'.
 * @param	func : bitmap function, 0: function, 1: gpio.
 *					  if byteId = SP1K_GPIO_BYTE_GEN1, bit [7:6] = GPIO[15:14];
 *					  if byteId = SP1K_GPIO_BYTE_GEN2, bit [1:0] = GPIO[17:16];
 *					  if byteId = SP1K_GPIO_BYTE_P1, bit [7:0] = P1[7:0].
 *					  Other bits: Not allowed.
 * @retval	None.
*/
void sp1kGpioByteFuncSet(UINT8 byteId,UINT8 msk,UINT8 func);

/**
 * @fn void sp1kGpioByteDirSet(UINT8 byteId, UINT8 msk, UINT8 dir)
 * @brief	Set gpio direction in byte.
 * @param	byteId :  SP1K_GPIO_BYTE_GEN1 for GPIO[15:14];
 *					  SP1K_GPIO_BYTE_GEN2 for GPIO[17:16];
 *                    SP1K_GPIO_BYTE_P1 for P1[7:0].
 * @param	msk : bitmap mask. please refer to param 'dir'.
 * @param	dir : bitmap direction, 0: input, 1: output.
 *					  if byteId = SP1K_GPIO_BYTE_GEN1, bit [7:6] = GPIO[15:14];
 *					  if byteId = SP1K_GPIO_BYTE_GEN2, bit [1:0] = GPIO[17:16];
 *					  if byteId = SP1K_GPIO_BYTE_P1, bit [7:0] = P1[7:0].
 *					  Other bits: Not allowed.
 * @retval	None.
*/
void sp1kGpioByteDirSet(UINT8 byteId,UINT8 msk,UINT8 dir);

/**
 * @fn void sp1kGpioByteOutSet(UINT8 byteId, UINT8 msk, UINT8 val)
 * @brief	Set gpio output in byte.
 * @param	byteId :  SP1K_GPIO_BYTE_GEN1 for GPIO[15:14];
 *					  SP1K_GPIO_BYTE_GEN2 for GPIO[17:16];
 *                    SP1K_GPIO_BYTE_P1 for P1[7:0].
 * @param	msk : bitmap mask. please refer to param 'val'.
 * @param	val : bitmap output value.
 *					  if byteId = SP1K_GPIO_BYTE_GEN1, bit [7:6] = GPIO[15:14];
 *					  if byteId = SP1K_GPIO_BYTE_GEN2, bit [1:0] = GPIO[17:16];
 *					  if byteId = SP1K_GPIO_BYTE_P1, bit [7:0] = P1[7:0].
 *					  Other bits: Not allowed.
 * @retval	None.
*/
void sp1kGpioByteOutSet(UINT8 byteId,UINT8 msk,UINT8 val);

/**
 * @fn UINT8 sp1kGpioByteInGet(UINT8 byteId, UINT8 msk)
 * @brief	Get gpio input in byte.
 * @param	byteId :  SP1K_GPIO_BYTE_GEN1 for GPIO[15:14];
 *					  SP1K_GPIO_BYTE_GEN2 for GPIO[17:16];
 *                    SP1K_GPIO_BYTE_P1 for P1[7:0].
 * @param	msk : bitmap mask. please refer to param 'val'.
 * @retval	bitmap input value, please refer to param 'val' in sp1kGpioByteOutSet().
*/
UINT8 sp1kGpioByteInGet(UINT8 byteId, UINT8 msk);

/**
 * @fn void sp1kPullEnSet(UINT8 byteId, UINT8 msk, UINT8 en)
 * @brief	Set pull high/low enable in byte.
 * @param	byteId :  byte ID, 0~6.
 * @param	msk : bitmap mask. please refer to param 'en'.
 * @param	en : bitmap function, 0: function, 1: gpio.
 *					  if byteId = 0, bit [0] = psen,
 *                                   bit [1] = romwr_n,
 *                                   bit [2] = fmgpio[0],
 *                                   bit [3] = fmgpio[1],
 *                                   bit [4] = fmgpio[5],
 *                                   bit [5] = fmgpio[6],
 *                                   bit [6] = fmgpio[7],
 *                                   bit [7] = fmgpio[8].
 *					  if byteId = 1, bit [0] = fmgpio[9],
 *                                   bit [1] = ma[0],
 *                                   bit [2] = ma[1],
 *                                   bit [3] = ma[2],
 *                                   bit [4] = ma[3],
 *                                   bit [5] = ma[4],
 *                                   bit [6] = ma[5],
 *                                   bit [7] = ma[6].
 *					  if byteId = 2, bit [0] = ma[7],
 *                                   bit [1] = ma[14],
 *                                   bit [2] = gpio[0],
 *                                   bit [3] = gpio[1],
 *                                   bit [4] = gpio[2],
 *                                   bit [5] = gpio[3],
 *                                   bit [6] = gpio[4],
 *                                   bit [7] = gpio[5].
 *					  if byteId = 3, bit [0] = gpio[6],
 *                                   bit [1] = gpio[7],
 *                                   bit [2] = gpio[9],
 *                                   bit [3] = gpio[10],
 *                                   bit [4] = gpio[11],
 *                                   bit [5] = gpio[13],
 *                                   bit [6] = gpio[14],
 *                                   bit [7] = gpio[15].
 *					  if byteId = 4, bit [0] = gpio[16],
 *                                   bit [1] = gpio[17],
 *                                   bit [2] = gpio[19],
 *                                   bit [3] = gpio[20],
 *                                   bit [4] = gpio[21],
 *                                   bit [5] = gpio[22],
 *                                   bit [6] = gpio[23],
 *                                   bit [7] = rgb[0].
 *					  if byteId = 5, bit [0] = rgb[1],
 *                                   bit [1] = rgb[2],
 *                                   bit [2] = rgb[3],
 *                                   bit [3] = rgb[4],
 *                                   bit [4] = rgb[5],
 *                                   bit [5] = rgb[6],
 *                                   bit [6] = rgb[7],
 *                                   bit [7] = rgb[8].
 *					  if byteId = 6, bit [0] = rgb[9],
 *                                   bit [1] = tggpio[4],
 *                                   bit [2] = tggpio[5].
 *					  Others: Not allowed.
 * @retval	None.
*/
void sp1kPullEnSet(UINT8 byteId, UINT8 msk, UINT8 en);

/**
 * @fn UINT8 sp1kPullEnGet(UINT8 byteId, UINT8 msk)
 * @brief	Get pull high/low enable in byte.
 * @param	byteId :  byte ID, 0~6.
 * @param	msk : bitmap mask. please refer to param 'en' in sp1kPullEnSet().
 * @retval	bitmap pull high/low, please refer to param 'en' in sp1kPullEnSet().
*/
UINT8 sp1kPullEnGet(UINT8 byteId, UINT8 msk);

UINT8 sp1kUsbStrSet(UINT32 resIdx );

#endif //__SP1K_UTILITY_H__

